package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.IdeaComment;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class IdeaCommentDao {
	DBHelp<IdeaComment> db=new DBHelp<IdeaComment>();
	public boolean save(IdeaComment ic){
		String sql="insert into t_ideacomment (id,content,createtime,t_idea_id,t_user_id) values (?,?,?,?,?)";
		return db.executeSQL(sql, ic.getId(),ic.getContent(),ic.getCreatetime(),ic.getIdeaId(),ic.getUserId());
	}
	public List<IdeaComment> findByIdeaid(String id){
		String sql="select id,content,createtime,t_idea_id,t_user_id from t_ideacomment where t_idea_id=?";
		return db.executeQueryForList(sql, new IdeacommentRowMapper(), id);
	}
	private class IdeacommentRowMapper implements RowMapper<IdeaComment>{

		public IdeaComment mapRow(ResultSet rs) throws SQLException {
			IdeaComment i=new IdeaComment();
			i.setId(rs.getString("id"));
			i.setContent(rs.getString("content"));
			i.setCreatetime(rs.getString("createtime"));
			i.setIdeaId(rs.getString("t_idea_id"));
			i.setUserId(rs.getString("t_user_id"));
			return i;
		}
		
	}
	public boolean delByIdeaid(String id) {
		String sql="delete from t_ideacomment where t_idea_id=?";
		return db.executeSQL(sql, id);
	}
}
